package com.FH.applyForm.officeServies.advance_types;

import com.FH.util.ResultDTO;

import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;

/**
 * Created by Administrator on 2016/10/12.
 */
@Path("/advancetypes")
@Produces(MediaType.APPLICATION_JSON)
@RequestScoped
public class AdvanceTypesResource {

   @EJB
    private AdvanceTypesDAO advanceTypesDAO;

    @GET
    @Path("/{search}&{page}&{size}")
    public ResultDTO getAdvanceTypesInfo(@PathParam("search") String search, @PathParam("page") String page, @PathParam("size") String size) {
        //添加分页查询
        if(null==page||"".equals(page)||"0".equals(page))
        {
            page = "1";	//默认从第1页开始查起
        }/*else
        {
            page =((Integer.parseInt(page)-1)*Integer.parseInt(size))+"";
        }*/
        if(null==size||"".equals(size))
        {
            size = "10";//默认10行数据
        }
        return advanceTypesDAO.getAdvanceTypesInfo(search,page, size);
    }

    /**
     * 添加
     */
    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO addAdvanceTypesInfo(AdvanceTypesPullDTO dataDTO) {

        return advanceTypesDAO.addAdvanceTypesInfo(dataDTO);
    }

    /**
     * 修改预支费用
     * @param dataDTO
     * @return
     */
    @PUT
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO updateAdvanceTypesInfo(AdvanceTypesPullDTO dataDTO) {

        return advanceTypesDAO.updateAdvanceTypesInfo(dataDTO);
    }

    /*
   删除
    */
    @PUT
    @Path("/delete")
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO deleteAdvanceTypesInfo(AdvanceTypesPullDTO dataDTO){

        return advanceTypesDAO.deleteAdvanceTypesInfo(dataDTO);

    }
}
